<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
        <meta charset='utf-8'>
        <title>Hootenanny</title>
        <link rel='stylesheet' href='css/base.css'>
        <link rel='stylesheet' href='css/reset.css'>
        <link rel='stylesheet' href='css/map.css'>
        <link rel='stylesheet' href='css/app.css'>
        <!---<link rel='stylesheet' href='css/feature-icons.css'>  iD 1.9.2 -->
        <link rel='stylesheet' href='css/dgcarousel.css'>
        <link rel='stylesheet' href='css/style2.css'>
        <link rel='stylesheet' href='css/hoot-style.css'>
        <link rel='stylesheet' href='css/translation_assistant.css'>
        <link rel='stylesheet' href='css/login.css'>
        <link rel='icon' href='css/img/favicon.png'>

        <!-- mobile devices -->
        <meta name='viewport' content='initial-scale=1.0 maximum-scale=1.0'>
        <meta name='apple-mobile-web-app-capable' content='yes' />
        <meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />

        <script src='js/lib/lodash.js'></script>
        <script src='js/lib/d3.v3.js'></script>
        <script src='js/lib/osmauth.js'></script>
        <script src='js/lib/jxon.js'></script>
        <script src='js/lib/d3.typeahead.js'></script>
        <script src='js/lib/d3.combobox.js'></script>
        <script src='js/lib/d3.geo.tile.js'></script>
        <script src='js/lib/d3.dimensions.js'></script>
        <script src='js/lib/d3.trigger.js'></script>
        <script src='js/lib/d3.jsonp.js'></script>
        <script src='js/lib/d3.keybinding.js'></script>
        <script src='js/lib/d3.curtain.js'></script>
        <script src='js/lib/d3.one.js'></script>
        <script src='js/lib/d3.value.js'></script>
        <script src='js/lib/d3-compat.js'></script>
        <script src='js/lib/bootstrap-tooltip.js'></script>
        <script src='js/lib/diff3.js'></script>
        <script src='js/lib/rbush.js'></script>
        <script src='js/lib/sexagesimal.js'></script>
        <script src='js/lib/togeojson.js'></script>
        <script src='js/lib/marked.js'></script>
        <script src='js/lib/moment.js'></script>

        <script src='js/id/id.js'></script>

        <script src='js/id/util.js'></script>
        <script src='js/id/util/session_mutex.js'></script>
        <script src='js/id/util/suggest_names.js'></script>

        <!--<script src='js/id/services/countrycode.js'></script>  iD 1.9.2 -->
        <script src='js/id/services.js'></script>
        <script src='js/id/services/dgservices.js'></script>
        <script src='js/id/services/taginfo.js'></script>
        <script src='js/id/services/wikipedia.js'></script>
        <script src='js/id/services/mapillary.js'></script>
        <script src='js/id/services/nominatim.js'></script>
        <script src='js/id/services/translationserver.js'></script>

        <script src='data/data_dev.js'></script>

        <script src="js/id/geo.js"></script>
        <script src="js/id/geo/extent.js"></script>
        <script src="js/id/geo/intersection.js"></script>
        <script src="js/id/geo/multipolygon.js"></script>
        <script src="js/id/geo/raw_mercator.js"></script>

        <script src='js/id/renderer/background.js'></script>
        <script src='js/id/renderer/background_source.js'></script>
        <script src='js/id/renderer/features.js'></script>
        <!--<script src='js/id/renderer/gpx_layer.js'></script>  iD 1.9.2 -->
        <script src='js/id/renderer/tile_layer.js'></script>
        <script src='js/id/renderer/footprint_layer.js'></script>
        <script src='js/id/renderer/arrow_layer.js'></script>
        <script src='js/id/renderer/review_layer.js'></script>
        <script src='js/id/renderer/map.js'></script>
        <!--<script src='js/id/renderer/mapillary_layer.js'></script>  iD 1.9.2 -->
        <script src='js/id/renderer/measure_layer.js'></script>

        <script src="js/id/svg.js"></script>
        <script src="js/id/svg/areas.js"></script>
        <script src="js/id/svg/defs.js"></script>
        <script src='js/id/svg/gpx.js'></script>
        <script src="js/id/svg/icon.js"></script>
        <script src="js/id/svg/labels.js"></script>
        <script src="js/id/svg/lines.js"></script>
        <script src='js/id/svg/mapillary_images.js'></script>
        <script src='js/id/svg/mapillary_signs.js'></script>
        <script src="js/id/svg/midpoints.js"></script>
        <script src="js/id/svg/osm.js"></script>
        <script src="js/id/svg/points.js"></script>
        <!--<script src="js/id/svg/surface.js"></script>  iD 1.9.2 -->
        <script src="js/id/svg/layers.js"></script>
        <script src="js/id/svg/tag_classes.js"></script>
        <script src="js/id/svg/turns.js"></script>
        <script src="js/id/svg/vertices.js"></script>

        <script src="js/id/ui.js"></script>
        <script src='js/id/ui/info.js'></script>
        <script src='js/id/ui/attribution.js'></script>
        <script src='js/id/ui/alert.js'></script>
        <script src='js/id/ui/radial_menu.js'></script>
        <script src='js/id/ui/inspector.js'></script>
        <script src='js/id/ui/modal.js'></script>
        <script src='js/id/ui/cmd.js'></script>
        <script src='js/id/ui/confirm.js'></script>
        <script src='js/id/ui/conflicts.js'></script>
        <script src='js/id/ui/commit.js'></script>
        <script src='js/id/ui/success.js'></script>
        <script src='js/id/ui/loading.js'></script>
        <script src='js/id/ui/account.js'></script>
        <script src='js/id/ui/background.js'></script>
        <script src='js/id/ui/map_data.js'></script>
        <script src='js/id/ui/map_in_map.js'></script>
        <script src='js/id/ui/modes.js'></script>
        <script src='js/id/ui/contributors.js'></script>
        <script src='js/id/ui/help.js'></script>
        <script src='js/id/ui/geolocate.js'></script>
        <script src='js/id/ui/notice.js'></script>
        <script src='js/id/ui/flash.js'></script>
        <script src='js/id/ui/feature_info.js'></script>
        <script src='js/id/ui/save.js'></script>
        <script src='js/id/ui/full_screen.js'></script>
        <script src='js/id/ui/tools.js'></script>
        <script src='js/id/ui/scale.js'></script>
        <script src='js/id/ui/splash.js'></script>
        <script src='js/id/ui/spinner.js'></script>
        <script src='js/id/ui/restore.js'></script>
        <script src='js/id/ui/tag_reference.js'></script>
        <script src='js/id/ui/map_metadata.js'></script>
        <script src='js/id/ui/tag_copy.js'></script>
        <script src='js/id/ui/paste_tags.js'></script>
        <script src='js/id/ui/preset.js'></script>
        <script src='js/id/ui/preset_icon.js'></script>
        <script src='js/id/ui/processing.js'></script>
        <script src='js/id/ui/lasso.js'></script>
        <script src='js/id/ui/source_switch.js'></script>
        <script src='js/id/ui/status.js'></script>
        <script src='js/id/ui/toggle.js'></script>
        <script src='js/id/ui/undo_redo.js'></script>
        <script src='js/id/ui/view_on_osm.js'></script>
		<script src='js/id/ui/warning.js'></script>
        <script src='js/id/ui/zoom.js'></script>
        <script src='js/id/ui/raw_tag_editor.js'></script>
        <script src='js/id/ui/raw_member_editor.js'></script>
        <script src='js/id/ui/raw_membership_editor.js'></script>
        <script src='js/id/ui/feature_list.js'></script>
        <script src='js/id/ui/selection_list.js'></script>
        <script src='js/id/ui/preset_list.js'></script>
        <script src='js/id/ui/entity_editor.js'></script>
        <script src='js/id/ui/disclosure.js'></script>
        <script src='js/id/ui/sidebar.js'></script>
        <script src='js/id/ui/dgcarousel.js'></script>
        <script src='js/id/ui/coordinates.js'></script>
        <script src='js/id/ui/schema_switcher.js'></script>

        <script src='js/id/ui/preset/access.js'></script>
        <script src='js/id/ui/preset/address.js'></script>
        <script src='js/id/ui/preset/check.js'></script>
        <script src='js/id/ui/preset/combo.js'></script>
        <script src='js/id/ui/preset/cycleway.js'></script>
        <script src='js/id/ui/preset/input.js'></script>
        <script src='js/id/ui/preset/localized.js'></script>
        <script src='js/id/ui/preset/maxspeed.js'></script>
        <script src='js/id/ui/preset/radio.js'></script>
        <script src='js/id/ui/preset/restrictions.js'></script>
        <script src='js/id/ui/preset/textarea.js'></script>
        <script src='js/id/ui/preset/wikipedia.js'></script>

        <script src='js/id/actions.js'></script>
        <script src="js/id/actions/add_midpoint.js"></script>
        <script src="js/id/actions/add_member.js"></script>
        <script src='js/id/actions/add_entity.js'></script>
        <script src='js/id/actions/add_vertex.js'></script>
        <script src='js/id/actions/change_member.js'></script>
        <script src='js/id/actions/change_preset.js'></script>
        <script src='js/id/actions/change_tags.js'></script>
        <script src='js/id/actions/circularize.js'></script>
        <script src='js/id/actions/connect.js'></script>
        <!--<script src='js/id/actions/copy_entity.js'></script>  iD 1.9.2 -->
        <script src='js/id/actions/copy_entities.js'></script>
        <script src='js/id/actions/delete_member.js'></script>
        <script src='js/id/actions/delete_multiple.js'></script>
        <script src='js/id/actions/delete_node.js'></script>
        <script src="js/id/actions/delete_relation.js"></script>
        <script src="js/id/actions/delete_way.js"></script>
        <script src='js/id/actions/discard_tags.js'></script>
        <script src='js/id/actions/disconnect.js'></script>
        <script src='js/id/actions/join.js'></script>
        <script src='js/id/actions/merge.js'></script>
        <script src='js/id/actions/merge_polygon.js'></script>
        <script src='js/id/actions/merge_remote_changes.js'></script>
        <script src='js/id/actions/move_node.js'></script>
        <script src='js/id/actions/move.js'></script>
        <script src='js/id/actions/noop.js'></script>
        <script src='js/id/actions/orthogonalize.js'></script>
        <script src='js/id/actions/rotate_way.js'></script>
        <script src='js/id/actions/restrict_turn.js'></script>
        <script src='js/id/actions/reverse.js'></script>
        <script src='js/id/actions/revert.js'></script>
        <script src='js/id/actions/straighten.js'></script>
        <script src='js/id/actions/split.js'></script>
        <script src='js/id/actions/unrestrict_turn.js'></script>
        <script src='js/id/actions/review.js'></script>

        <script src='js/id/behavior.js'></script>
        <script src='js/id/behavior/add_way.js'></script>
        <!-- <script src='js/id/behavior/breathe.js'></script> Removed from 1.9.2 for flashing features-->
        <script src='js/id/behavior/copy.js'></script>
        <script src='js/id/behavior/drag.js'></script>
        <script src='js/id/behavior/draw.js'></script>
        <script src='js/id/behavior/draw_way.js'></script>
        <script src='js/id/behavior/edit.js'></script>
        <script src='js/id/behavior/hash.js'></script>
        <script src='js/id/behavior/hover.js'></script>
        <script src='js/id/behavior/lasso.js'></script>
        <script src='js/id/behavior/paste.js'></script>
        <script src='js/id/behavior/select.js'></script>
        <script src='js/id/behavior/tail.js'></script>
        <script src='js/id/behavior/measure_draw_line.js'></script>
        <script src='js/id/behavior/measure_draw_area.js'></script>
        <script src='js/id/behavior/clip.js'></script>

        <script src='js/id/modes.js'></script>
        <script src='js/id/modes/add_area.js'></script>
        <script src='js/id/modes/add_point.js'></script>
        <script src='js/id/modes/add_line.js'></script>
        <script src='js/id/modes/browse.js'></script>
        <script src='js/id/modes/drag_node.js'></script>
        <script src='js/id/modes/draw_area.js'></script>
        <script src='js/id/modes/draw_line.js'></script>
        <script src='js/id/modes/move.js'></script>
        <script src='js/id/modes/rotate_way.js'></script>
        <script src='js/id/modes/save.js'></script>
        <script src='js/id/modes/select.js'></script>
        <script src='js/id/modes/measure_add_line.js'></script>
        <script src='js/id/modes/measure_add_area.js'></script>
        <script src='js/id/modes/clip_bounding_box.js'></script>

        <script src='js/id/operations.js'></script>
        <script src='js/id/operations/continue.js'></script>
        <script src='js/id/operations/circularize.js'></script>
        <script src='js/id/operations/orthogonalize.js'></script>
        <script src='js/id/operations/straighten.js'></script>
        <script src='js/id/operations/delete.js'></script>
        <script src='js/id/operations/disconnect.js'></script>
        <script src='js/id/operations/merge.js'></script>
        <script src='js/id/operations/move.js'></script>
        <script src='js/id/operations/rotate.js'></script>
        <script src='js/id/operations/reverse.js'></script>
        <script src='js/id/operations/split.js'></script>
        <script src='js/id/operations/toggle.js'></script>
        <script src='js/id/operations/review.js'></script>

        <script src='js/id/core/connection.js'></script>
        <script src='js/id/core/difference.js'></script>
        <script src='js/id/core/entity.js'></script>
        <script src='js/id/core/graph.js'></script>
        <script src='js/id/core/history.js'></script>
        <script src='js/id/core/node.js'></script>
        <script src='js/id/core/relation.js'></script>
        <script src='js/id/core/way.js'></script>
        <script src='js/id/core/tree.js'></script>
        <!--<script src='js/id/core/oneway_tags.js'></script>  iD 1.9.2 -->
        <script src='js/id/core/tags.js'></script>

        <script src='js/id/presets.js'></script>
        <script src='js/id/presets/preset.js'></script>
        <script src='js/id/presets/category.js'></script>
        <script src='js/id/presets/collection.js'></script>
        <script src='js/id/presets/field.js'></script>

        <!--<script src='js/id/validate.js'></script>  iD 1.9.2 -->
        <script src='js/id/validations.js'></script>
        <script src='js/id/validations/deprecated_tag.js'></script>
        <script src='js/id/validations/many_deletions.js'></script>
        <script src='js/id/validations/missing_tag.js'></script>
        <script src='js/id/validations/tag_suggests_area.js'></script>

        <script src='js/lib/locale.js'></script>
        <script src='data/introGraph.js'></script>
        <script src='js/hoot/Hoot.js'></script>
        <script src='js/hoot/tools.js'></script>


        <script src='js/hoot/lib/FileSaver.js'></script>



        <script src="js/id/svg/far.js"></script>


        <script src='js/hoot/model/Model.js'></script>
        <script src='js/hoot/model/Export.js'></script>
        <script src='js/hoot/model/Folders.js'></script>
        <script src='js/hoot/model/Import.js'></script>
        <script src='js/hoot/model/Layers.js'></script>
        <script src='js/hoot/model/Conflicts.js'></script>
        <script src='js/hoot/model/Conflate.js'></script>
        <script src='js/hoot/model/BasemapDataset.js'></script>
        <script src='js/hoot/model/rest.js'></script>

        <script src='js/hoot/view/View.js'></script>
        <script src='js/hoot/view/VersionInfo.js'></script>
        <script src='js/hoot/view/Login.js'></script>
        <script src='js/hoot/view/utilities/Utilities.js'></script>
        <script src='js/hoot/view/utilities/Dataset.js'></script>
        <!-- <script src='js/hoot/view/utilities/WfsDataset.js'></script> -->
        <script src='js/hoot/view/utilities/BasemapDataset.js'></script>
        <script src='js/hoot/view/utilities/Translation.js'></script>
        <script src='js/hoot/view/utilities/About.js'></script>
        <script src='js/hoot/view/utilities/ReviewBookmarks.js'></script>
        <script src='js/hoot/view/utilities/ReviewBookmarkNotes.js'></script>

        <script src='js/hoot/control/Control.js'></script>
        <script src='js/hoot/control/Conflate.js'></script>
        <script src='js/hoot/control/conflate/Symbology.js'></script>
        <script src='js/hoot/control/conflate/AdvancedOptions.js'></script>
        <script src='js/hoot/control/conflate/advanced_options/FieldsGenerator.js'></script>
        <script src='js/hoot/control/conflate/advanced_options/FieldsRetriever.js'></script>
        <script src='js/hoot/control/conflate/advanced_options/SelectionDisplay.js'></script>
        <script src='js/hoot/control/conflate/advanced_options/SelectionRetriever.js'></script>
        <script src='js/hoot/control/conflate/advanced_options/FieldsetLogic.js'></script>

        <script src='js/hoot/control/Import.js'></script>
        <script src='js/hoot/control/View.js'></script>
        <script src='js/hoot/control/Conflicts.js'></script>
        <script src='js/hoot/control/Validation.js'></script>
        <script src='js/hoot/control/translation_assistant.js'></script>
        <script src='js/hoot/control/utilities/Utilities.js'></script>
        <script src='js/hoot/control/utilities/Translation.js'></script>
        <script src='js/hoot/control/utilities/BasemapDataset.js'></script>
        <script src='js/hoot/control/utilities/Folder.js'></script>
        <!-- <script src='js/hoot/control/utilities/WfsDataset.js'></script> -->
        <script src='js/hoot/control/utilities/Validation.js'></script>
        <script src='js/hoot/control/utilities/Filter.js'></script>
        <script src='js/hoot/control/utilities/ExportDataset.js'></script>
        <script src='js/hoot/control/utilities/BulkModifyDataset.js'></script>
        <script src='js/hoot/control/utilities/ModifyDataset.js'></script>
        <script src='js/hoot/control/utilities/ImportDataset.js'></script>
        <script src='js/hoot/control/utilities/BulkImportDataset.js'></script>
        <script src='js/hoot/control/utilities/BulkExportDataset.js'></script>
        <script src='js/hoot/control/utilities/ImportDirectory.js'></script>
        <script src='js/hoot/control/utilities/ClipDataset.js'></script>
        <script src='js/hoot/control/utilities/SetTagOverrides.js'></script>

        <script src='js/hoot/control/conflicts/Actions.js'></script>
        <script src='js/hoot/control/conflicts/actions/IdGraphSynch.js'></script>
        <script src='js/hoot/control/conflicts/actions/PoiMerge.js'></script>
        <script src='js/hoot/control/conflicts/actions/ReviewResolution.js'></script>
        <script src='js/hoot/control/conflicts/actions/TraverseReview.js'></script>
        <script src='js/hoot/control/conflicts/actions/ShareReview.js'></script>

        <script src='js/hoot/control/conflicts/Info.js'></script>
        <script src='js/hoot/control/conflicts/info/MetaData.js'></script>
        <script src='js/hoot/control/conflicts/info/ReviewTable.js'></script>

        <script src='js/hoot/control/conflicts/Map.js'></script>
        <script src='js/hoot/control/conflicts/map/FeatureHighlighter.js'></script>
        <script src='js/hoot/control/conflicts/map/FeatureNavigator.js'></script>
        <script src='js/hoot/control/conflicts/map/ReviewArrowRenderer.js'></script>

        <script src='js/hoot/Ui.js'></script>
        <script src='js/hoot/ui/FormFactory.js'></script>
        <script src='js/hoot/ui/HootFormBase.js'></script>
        <script src='js/hoot/ui/HootFormReviewNote.js'></script>


    </head>
    <body>
        <div id='id-container'></div>
        <script>
            function findGetParameter(parameterName) {
                var result = null,
                    tmp = [];
                location.search
                    .substr(1)
                    .split("&")
                    .forEach(function (item) {
                      tmp = item.split("=");
                      if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
                    });
                return result;
            }
            var oauth_token = findGetParameter('oauth_token');
            var oauth_verifier = findGetParameter('oauth_verifier');
            if(oauth_token && oauth_verifier) {
                // if we have these tokens, this is the spawned popup-
                d3.json('../hoot-services/auth/oauth1/verify?oauth_verifier=' + oauth_verifier + '&oauth_token=' + oauth_token, function(e, r) {
                    if(e) {
                        console.warn('failed to verify oauth tokens w/ provider:');
                        console.warn('XMLHttpRequest.status', e.status || null);
                        console.warn('XMLHttpRequest.responseText ', e.responseText || null);

                        if(opener) {
                            window.onbeforeunload = function() {
                                opener.oAuthDone(e, null);
                            }
                            window.close();
                        } else {
                            window.alert('Failed to complete oauth handshake. Check console for details & retry.');
                            // clear oauth params.
                            window.history.pushState({}, document.title, window.location.pathname);
                        }

                    } else {
                        if(opener) {
                            window.onbeforeunload = function() {
                                opener.oAuthDone(null, r);
                            }
                            window.close();
                        } else {
                            // force refresh.
                            window.location.reload(true);
                        }
                    }
                });
            } else {
                iD.data.load(function() {
                    if(iD.data.buildInfo && iD.data.buildInfo.version){
                        iD.version = iD.data.buildInfo.version + "(Hootenanny)";
                    } else {
                        iD.version = "Unknown(Hootenanny)";
                    }
                    id = iD().presets(iD.data.presets)
                        .imagery(iD.data.imagery)
                        .taginfo(iD.services.taginfo())
                        .assetPath('dist/');

                    function load() {
                        // unload landing page.
                        Hoot.view.unload_login();

                        // load application.
                        id.hoot().load(function() {
                            d3.select('#id-container').call(id.ui());
                        });
                    }
                    // launch popup & attach callback function
                    // to child window.
                    function launch_login(oauth_redirect_url) {
                        window.open(oauth_redirect_url, "hootenanny_login_redirect", "width=500,height=800,toolbar=no,status=no,menubar=no");

                        window.oAuthDone = function(e, user_object) {
                            if(e) {
                                console.warn('failed to verify oauth tokens w/ provider:');
                                console.warn('XMLHttpRequest.status', e.status || null);
                                console.warn('XMLHttpRequest.responseText ', e.responseText || null);

                                window.alert('Failed to complete oauth handshake. Check console for details & retry.');
                                window.history.pushState({}, document.title, window.location.pathname);

                            } else {
                                if(localStorage) {
                                    localStorage.setItem('user', JSON.stringify(user_object));
                                }
                                load();
                            }
                        }
                    }
                    Hoot.model.REST('servicesVersionInfo', function(services_version_info) {
                        if(services_version_info && services_version_info.error) {
                            // redirect.
                            Hoot.model.REST('getOAuthRedirectURL', function(oauth_redirect_url) {
                                if(oauth_redirect_url && oauth_redirect_url.error) {
                                    // failed to get oauth redirect url from hoot-services.
                                    // must be offline or misconfigured.
                                    console.error(oauth_redirect_url);
                                    window.alert('Failed to retrieve authentication environment from services. Check console for details.');

                                } else {
                                    // render landing page.
                                    Hoot.view.login(function() {
                                        launch_login(oauth_redirect_url);
                                    }, function() {
                                        window.location = oauth_redirect_url;
                                    }, 'dist/');

                                    launch_login(oauth_redirect_url);
                                }
                            });
                        } else {
                            load();
                        }
                    });
                });
            }
        </script>
    </body>
</html>
